# -*- coding:utf-8 *-
# 项目       :    易聊测试
# 文件       :    weight_test.py
# 作者       :    zc
# 时间       :    2021/9/17  4:50 下午
# IDE       :    PyCharm

#次脚本仅对权重算法进行较小压力测试

import json
import requests
from locust import between, HttpUser, TaskSet, task, constant
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)


class weight(TaskSet):
    # 访问落地页
    @task(1)
    def get_yiliao(self):
        #定义请求头
        header ={'User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 '
             '(KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'}
        req = self.client.get('file:///Users/a1234/Downloads/%E6%9D%83%E9%87%8D%E8%AE%BF%E9%97%AE%E9%A1%B5.html'
                              ,headers=header,verify=False)
        if req.status_code ==200:
            print('请求通过，正常进行访问')
        else:
            print('报错喽')

class webUser(HttpUser):
    task_set =weight
    min_wait = 10000
    max_wait = 60000

if __name__ == '__main__':
    import os
    os.system('locust -f weight_test.py')
